#ifndef CS1237SUPPORT_CODA_CS1237_H
#define CS1237SUPPORT_CODA_CS1237_H
#include <Arduino.h>

#define SPEED_10Hz      0b00
#define SPEED_40Hz      0b01
#define SPEED_640Hz     0b10
#define SPEED_1280Hz    0b11

#define GAIN_1X         0b00
#define GAIN_2X         0b01
#define GAIN_64X        0b10
#define GAIN_128X       0b11

#define CH_A            0b00
#define CH_TEMP         0b10
#define CH_SC           0b11

#define REF_OUT_ON      0b0
#define REF_OUT_OFF     0b1

#define PIN_IN()      pinMode(DIO,INPUT);
#define PIN_OUT()     pinMode(DIO,OUTPUT);
#define D_HIGH()      digitalWrite(DIO,HIGH);
#define D_LOW()       digitalWrite(DIO,LOW);

#define C_HIGH()      digitalWrite(CLK,HIGH);
#define C_LOW()       digitalWrite(CLK,LOW);

#define D_IN()        digitalRead(DIO)


#define delay_ms(ms)    delay(ms);
#define delay_us(us)    delayMicroseconds(us);

#define GEN_CLK()       C_HIGH();delay_us(1);D_HIGH();C_LOW();delay_us(1);


class coda_cs1237
{
private:
    uint8_t DIO=0;
    uint8_t CLK=1;
public:
    void begin(uint8_t dio=0,uint8_t clk=1);
    void setpin(uint8_t dio=0,uint8_t clk=1);
    void config(uint8_t speed = SPEED_40Hz  ,       //设置采样率
                uint8_t channel= CH_A       ,       //采样通道
                uint8_t gain = GAIN_1X      ,       //
                uint8_t refout =REF_OUT_ON          //
                );
    uint8_t config(void);
    int32_t read(void);
};

#endif //CS1237SUPPORT_CODA_CS1237_H
